package cn.lystudio.rohm_time_op.satoken;

import cn.dev33.satoken.stp.StpInterface;
import cn.dev33.satoken.stp.StpUtil;
import cn.lystudio.rohm_time_op.entity.dto.UserDepartmentDTO;
import cn.lystudio.rohm_time_op.entity.dto.UserRoleDTO;
import cn.lystudio.rohm_time_op.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;

@Component
public class MyStpInterfaceImpl implements StpInterface {
    private UserService userService;

    @Autowired
    @Lazy
    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    /**
     * 获取用户制造部权限
     * @param loginID
     * @param s
     * @return
     */
    @Override
    public List<String> getPermissionList(Object loginID, String s) {
        List<String> topDeptPermissionList = new ArrayList<>();
        UserDepartmentDTO userDepartmentDTO = userService.get1UserDepartment_Usable(StpUtil.getLoginIdAsString());
        topDeptPermissionList.add(userDepartmentDTO.getDepartmentsPO().getDepartmentID().toString());
        return topDeptPermissionList;
    }

    /**
     * 获取用户角色
     * @param loginID
     * @param s
     * @return
     */
    @Override
    public List<String> getRoleList(Object loginID, String s) {
        List<String> roleList=new ArrayList<>();
        UserRoleDTO userRoleDTO = userService.get1UserRole_Usable(loginID.toString());
        roleList.add(userRoleDTO.getRolesPO().getRoleID().toString());
        return roleList;
    }
}
